package com.example.foreach;

import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.util.concurrent.TimeUnit;

/**
 * @author csp 2022-10-18
 */
@BenchmarkMode(Mode.AverageTime)
@Warmup(iterations = 1, time = 5)
@Measurement(iterations = 5, time = 5)
@Threads(1)
@Fork(1)
@State(value = Scope.Benchmark)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public class ForTest {

    @Benchmark
    public void fortest(){
        long num = 0;
        for (int i = 0; i < 10000; i++) {
            for (int j = 0; j < 10000000000L; j++) {
                num++;
            }
        }
    }
    @Benchmark
    public void fortest1(){
        long num = 0;
        for (int i = 0; i < 10000000000L; i++) {
            for (int j = 0; j < 10000; j++) {
                num++;
            }
        }
    }





    public static void main(String[] args) throws RunnerException {
        Options options = new OptionsBuilder()
                .include(ForTest.class.getSimpleName())
                .result("result.json")
                .build();
        new Runner(options).run();
    }
}
